package org.bigk.invoices.model;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.bigk.invoices.utils.TextUtils;

@Entity
@Table(name = "invoices_purchasers")
public class InvoicePurchaser implements Serializable, Cloneable {

	private static final long serialVersionUID = 7224945167205375617L;

	@Id
	@GeneratedValue
	@Column(name = "id")
	private Long id;

	@Column(name = "invoice_id", insertable = false, updatable = false)
	private Long invoiceId;
	
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name = "invoice_id", insertable = true, updatable = true)
	private Invoice invoice;

	@Column(name = "purchaser_role_id")
	private Long purchaserRoleId;

	@ManyToOne
	@JoinColumn(name = "purchaser_role_id", insertable = false, updatable = false)
	private PurchaserRole purchaserRole;

	@Column(name = "name")
	private String name;

	@Column(name = "address")
	private String address;

	@Column(name = "nip")
	private String nip;

	public InvoicePurchaser() {
		super();
	}
	
	public InvoicePurchaser clone() throws CloneNotSupportedException {
		return (InvoicePurchaser) super.clone();
	}
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getInvoiceId() {
		return invoiceId;
	}

	public void setInvoiceId(Long invoiceId) {
		this.invoiceId = invoiceId;
	}

	public Long getPurchaserRoleId() {
		return purchaserRoleId;
	}

	public void setPurchaserRoleId(Long purchaserRoleId) {
		this.purchaserRoleId = purchaserRoleId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getNip() {
		return nip;
	}

	public void setNip(String nip) {
		this.nip = nip;
	}

	public Invoice getInvoice() {
		return invoice;
	}

	public void setInvoice(Invoice invoice) {
		this.invoice = invoice;
	}

	public PurchaserRole getPurchaserRole() {
		return purchaserRole;
	}

	public void setPurchaserRole(PurchaserRole purchaserRole) {
		this.purchaserRole = purchaserRole;
	}

	public String getNameHTML() {
		return TextUtils.convert2HtmlText(name);
	}

	public String getAddressHTML() {
		return TextUtils.convert2HtmlText(address);
	}

	public String getNipHTML() {
		return TextUtils.convert2HtmlText(nip);
	}

	public String getNameJS() {
		return TextUtils.convert2JsText(name);
	}

	public String getAddressJS() {
		return TextUtils.convert2JsText(address);
	}

	public String getNipJS() {
		return TextUtils.convert2JsText(nip);
	}

}
